import { sign } from '@/utils/sign'
import storage from 'store'
import { ACCESS_TOKEN } from '@/store/mutation-types'

export function setHeaders (parameter) {
  const token = storage.get(ACCESS_TOKEN)
  const config = {}
  config.data = parameter
  const headers = {
    'Content-Type': 'application/json;charset=UTF-8'
  }
  if ((typeof (token) !== 'undefined') || (typeof (token) === 'object') || token) {
    headers.token = token
    config.data.token = token
  }
  const resultConfig = sign(config).headers
  return Object.assign(resultConfig, headers)
}

export function post (api, parameter) {
  const obj = {
    url: api,
    method: 'post',
    headers: setHeaders(parameter),
    data: parameter
  }
  return obj
}
